//spu相关的接口函数

import request from "@/utils/request";
import type {
  SpuItem,
  BaseSaleAttrList,
  SpuListApiParams,
  SpuListRes,
  SpuImageList,
  SpuSaleAttrList,
} from "./models/spuModel";

enum Api {
  //spu列表
  spuListUrl = "/admin/product",
  //销售属性
  baseSaleAttrListUrl = "/admin/product/baseSaleAttrList",
  //添加spu
  addSpuApiUrl = "/admin/product/saveSpuInfo",
  //获取更新sku图片列表
  getSpuImageListUrl = "/admin/product/spuImageList",
  //获取更新sku销售属性
  getSpuSaleAttrListUrl = "/admin/product/spuSaleAttrList",
  //修改spu
  setSpuUrl = "/admin/product/updateSpuInfo",
  //删除spu
  delSpuUrl = "/admin/product/deleteSpu",
}

/**
 *获取spu列表接口函数
 * @param SpuListApiParams
 * @returns  SpuListRes
 */
export const getSpuListApi = ({
  page,
  limit,
  category3Id,
}: SpuListApiParams) => {
  return request.get<any, SpuListRes>(`${Api.spuListUrl}/${page}/${limit}`, {
    params: {
      category3Id,
    },
  });
};

/**
 * //获取销售属性的接口函数
 * @returns BaseSaleAttrList
 */
export const baseSaleAttrListApi = () => {
  return request.get<any, BaseSaleAttrList>(Api.baseSaleAttrListUrl);
};

/**
 * //添加spu的接口函数
 * @param data
 * @returns null
 */
export const addSpuApi = (data: SpuItem) => {
  return request.post<any, null>(Api.addSpuApiUrl, data);
};

/**
 * 获取更新spu图片的接口函数
 * @param id
 * @returns SpuImageItem
 */
export const getSpuImageListApi = (id: number) => {
  return request.get<any, SpuImageList>(Api.getSpuImageListUrl + `/${id}`);
};

/**
 * 获取更新spu销售属性的接口函数
 * @param id
 * @returns SpuSaleAttrValueList
 */
export const getSpuSaleAttrListApi = (id: number) => {
  return request.get<any, SpuSaleAttrList>(
    Api.getSpuSaleAttrListUrl + `/${id}`
  );
};

/**
 * 修改spu的接口函数
 * @param data SpuItem
 * @returns null
 */
export const setSpuApi = (data: SpuItem) => {
  return request.post<any, null>(Api.setSpuUrl, data);
};

/**
 * 删除SPU的接口函数
 * @param id
 * @returns null
 */
export const delSpuApi = (id: number) => {
  return request.delete<any, null>(Api.delSpuUrl + `/${id}`);
};
